package com.util.zk;
import java.io.FileInputStream;
import java.sql.*;
import java.util.Properties;

public class Dbutil {
    public static Connection getConnection() throws Exception {

        Properties pt = new Properties();
        FileInputStream fis = new FileInputStream(Dbutil.class.getResource("/").getPath()+"db.properties");
        pt.load(fis);
        String driver = pt.getProperty("driver");
        String url = pt.getProperty("url");
        String username = pt.getProperty("username");
        String password = pt.getProperty("password");
        fis.close();

        Class.forName(driver);
        return DriverManager.getConnection(url, username, password);
    }


    public static void closeAll(ResultSet ret, PreparedStatement ppst, Connection con) {
        try {
            if (ret != null) {
                ret.close();
            }
            if (ppst != null) {
                ppst.close();
            }
            if (con != null) {
                con.close();
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

}